﻿using System;
using System.Net;
using System.Xml.Serialization;

namespace Toybox.NicoSharp.Seiga.Primitives
{
	using Extensions;
	using Utilities;

	public enum ActionType
	{
		count,
		default_flash_request,
	}

	[XmlRoot("response")]
	public class PostKey
	{

		#region [Static]

		public static PostKey GetKey(string id, ActionType action, CookieCollection cookies = null)
		{
			return GetKey(id, action.ToString(), cookies);
		}

		public static PostKey GetKey(string id, string action, CookieCollection cookies = null)
		{
			id = Uri.EscapeDataString(id).Replace("(", "%28").Replace(")", "%29");

			string url = NicoUrls.SeigaApi + "keys/postkey";
			string data = ("key_id=" + id + "&a=" + action).Replace("_", "%5F");
			string xml = NicoWebClient.Post(url, data, cookies.Coerce());
			return Deserializer.XmlDeserializer<PostKey>(xml);
		}

		#endregion [Static]


		#region Public Members

		public string action;

		public int time;

		public string hash;

		#endregion Public Members

	}
}
